#include "fufu_type.h"

FuFuType::FuFuType(int type_id) : type_id(type_id)
{

}

FuFuBasicType::FuFuBasicType() : FuFuType(FuFuBasicType::TYPEID)
{

}
FuFuBasicType::FuFuBasicType(int btype_id) : FuFuType(FuFuBasicType::TYPEID), basic_type_id(btype_id)
{

}

std::vector<std::string> FuFuBasicType::type_name = {
	"i1",
	"i8",
	"i32",
	"float",
	"double",
	"i8*"
};

std::string FuFuBasicType::getTypeString()
{
	return type_name[basic_type_id];
}

FuFuArray::FuFuArray(int len, std::shared_ptr<FuFuType> under) : FuFuType(FuFuArray::TYPEID), len(len), under_type(under)
{

}

std::string FuFuArray::getTypeString()
{
	std::string _type_string;
	if (len >= 0)
	{
		_type_string.append("[");
		_type_string.append(std::to_string(len));
		_type_string.append(" x ");
		_type_string.append(under_type->getTypeString());
		_type_string.append("]");
	}
	else
	{
		_type_string.append(under_type->getTypeString());
		_type_string.append("*");
	}
	return _type_string;
}
FuFuArray::FuFuArray(const FuFuArray& other) : FuFuType(FuFuArray::TYPEID)
{
	_ASSERTE(false);

}

FuFuType& FuFuArray::operator=(FuFuType& rhs)
{
	_ASSERTE(false);
	return *this;
}

FuFuType& FuFuBasicType::operator=(FuFuType& rhs)
{
	_ASSERTE(false);
	return *this;
}

std::shared_ptr<FuFuType> FuFuBasicType::clone()
{

	std::shared_ptr<FuFuBasicType> copy = std::make_shared<FuFuBasicType>();
	copy->basic_type_id = this->basic_type_id;
	return copy;
}
std::shared_ptr<FuFuType> FuFuArray::clone()
{
	std::shared_ptr<FuFuArray> copy = std::make_shared<FuFuArray>(this->len, this->under_type->clone());
	return copy;
}

FuFuPointer::FuFuPointer(std::shared_ptr<FuFuType> under) : FuFuArray(-1, under)
{
	type_id = FuFuPointer::TYPEID;
}

std::shared_ptr<FuFuType> FuFuPointer::clone()
{
	std::shared_ptr<FuFuPointer> copy = std::make_shared<FuFuPointer>(this->under_type->clone());
	return copy;
}

std::string FuFuPointer::getTypeString()
{
	std::string _type_string;
	_type_string.append(under_type->getTypeString());
	_type_string.append("*");
	return _type_string;
}